<script lang="ts" setup>
import { reactive, onMounted } from 'vue'
import baseDefault from './baseDefault.vue'
import customAction from './customAction.vue'
import hiddenButton from './hiddenButton.vue'
import enableInline from './enableInline.vue'
import enableRule from './enableRule.vue'
import formType from './formType.vue'
import searchForm from './searchForm.vue'
import dialogForm from './dialogForm.vue'
import drawerForm from './drawerForm.vue'
import QuickCode from '@/components/QuickCode/index.vue'
import { getFile } from '@/api/file'

const form = reactive({
  defaultCode: '',
  customActionCode: '',
  hiddenButtonCode: '',
  enableInlineCode: '',
  enableRuleCode: '',
  formTypeCode: '',
  searchFormCode: '',
  dialogFormCode: '',
  drawerFormCode: '',
})
onMounted(() => {
  getFile('/template/form/baseDefault.vue').then((res: any) => {
    form.defaultCode = res
  })
  getFile('/template/form/customAction.vue').then((res: any) => {
    form.customActionCode = res
  })
  getFile('/template/form/hiddenButton.vue').then((res: any) => {
    form.hiddenButtonCode = res
  })
  getFile('/template/form/enableInline.vue').then((res: any) => {
    form.enableInlineCode = res
  })
  getFile('/template/form/enableRule.vue').then((res: any) => {
    form.enableRuleCode = res
  })
  getFile('/template/form/formType.vue').then((res: any) => {
    form.formTypeCode = res
  })
  getFile('/template/form/searchForm.vue').then((res) => {
    form.searchFormCode = res
  })
  getFile('/template/form/dialogForm.vue').then((res) => {
    form.dialogFormCode = res
  })
  getFile('/template/form/drawerForm.vue').then((res) => {
    form.drawerFormCode = res
  })
})
</script>
<template>
  <div class="component-demo">
    <el-card>
      <template #header>
        <div class="card-header card-name">
          <h2>默认</h2>
        </div>
        <div class="card-description">
          <p>常规表单</p>
        </div>
      </template>
      <base-default></base-default>
      <quick-code :autodetect="true" :code="form.defaultCode"></quick-code>
    </el-card>
    <el-card class="item" shadow="always">
      <template #header>
        <div class="card-header card-name">
          <h2>自定义表单操作按钮</h2>
        </div>
        <div class="card-description">
          <p>
            通过设置属性:action-slot="true"启用插槽，然后通过插槽自定义表单操作按钮
          </p>
        </div>
      </template>
      <custom-action></custom-action>
      <quick-code :autodetect="true" :code="form.customActionCode"></quick-code>
    </el-card>
    <el-card class="item" shadow="always">
      <template #header>
        <div class="card-header card-name">
          <h2>隐藏表单按钮</h2>
        </div>
        <div class="card-description">
          <p>通过设置属性:hidden-action="true"隐藏表单操作按钮</p>
        </div>
      </template>
      <hidden-button></hidden-button>
      <quick-code :autodetect="true" :code="form.hiddenButtonCode"></quick-code>
    </el-card>
    <el-card class="item" shadow="always">
      <template #header>
        <div class="card-header card-name">
          <h2>行内表单</h2>
        </div>
        <div class="card-description">
          <p>通过设置属性:inline="true"启用行内表单</p>
        </div>
      </template>
      <enable-inline></enable-inline>
      <quick-code :autodetect="true" :code="form.enableInlineCode"></quick-code>
    </el-card>
    <el-card class="item" shadow="always">
      <template #header>
        <div class="card-header card-name">
          <h2>表单验证</h2>
        </div>
        <div class="card-description">
          <p>通过设置属性formItems中的prop和rules校验表单</p>
        </div>
      </template>
      <enable-rule></enable-rule>
      <quick-code :autodetect="true" :code="form.enableRuleCode"></quick-code>
    </el-card>
    <el-card class="item" shadow="always">
      <template #header>
        <div class="card-header card-name">
          <h2>表单类型</h2>
        </div>
        <div class="card-description">
          <p>
            通过设置属性formType="form",默认值form，可选值：form|search|add|edit|detail
          </p>
        </div>
      </template>
      <form-type></form-type>
      <quick-code :autodetect="true" :code="form.formTypeCode"></quick-code>
    </el-card>
    <el-card class="item" shadow="always">
      <template #header>
        <div class="card-header card-name">
          <h2>搜索表单</h2>
        </div>
        <div class="card-description">
          <p>默认搜索表单，如需更灵活的配置，请使用search组件</p>
        </div>
      </template>
      <search-form></search-form>
      <quick-code :autodetect="true" :code="form.searchFormCode"></quick-code>
    </el-card>
    <el-card class="item" shadow="always">
      <template #header>
        <div class="card-header card-name">
          <h2>弹窗表单</h2>
        </div>
        <div class="card-description">
          <p>使用默认表单，如需更灵活的配置，请使用参考表单组件</p>
        </div>
      </template>
      <dialog-form></dialog-form>
      <quick-code :autodetect="true" :code="form.dialogFormCode"></quick-code>
    </el-card>
    <el-card class="item" shadow="always">
      <template #header>
        <div class="card-header card-name">
          <h2>抽屉表单</h2>
        </div>
        <div class="card-description">
          <p>使用默认表单，如需更灵活的配置，请使用参考表单组件</p>
        </div>
      </template>
      <drawer-form></drawer-form>
      <quick-code :autodetect="true" :code="form.drawerFormCode"></quick-code>
    </el-card>
  </div>
</template>
<style lang="scss" scoped>
.component-demo {
  .card-name {
  }
  .card-description {
    margin-top: 10px;
  }
  .item {
    margin-top: 10px;
  }
}
</style>
